package com.factory._13observe.demo1;

import java.util.Enumeration;
import java.util.Vector;

/**
 * @author Qinye
 * @date 2023/8/13 15:55
 */
public class ConcreteSubject implements Subject {
    private Vector<Observer> vector = new Vector();

    @Override
    public void attach(Observer observer) {
        vector.addElement(observer);
    }

    @Override
    public void detach(Observer observer) {
        vector.removeElement(observer);
    }

    @Override
    public void notifyObservers() {

        Enumeration<Observer> enumeration = observers();
        while (enumeration.hasMoreElements()) {
            ((Observer) enumeration.nextElement()).update();
        }
    }

    public Enumeration observers() {
        return (((Vector) vector.clone()).elements());
    }
}
